<?php

require_once("Model/MemberCatalogModel.php");

require_once("View/BoatView.php");

class MemberView 
{
	//Privata strängar
	private $getFirstName = "firstname";
	private $getLastName = "lastname";	
	private $getSocialNumber = "socialnumber";	
	private $getCreateSubmit = "createsubmit";
	private $getDeleteButton = "delete";
	private $getUpdateButton = "update";
	
	//Konstanter
	const ADD_MEMBER_HEADER = 1;
	const LIST_MEMBER_HEADER = 2;
	const FULL_LIST_MEMBER_HEADER = 3;
	const SPECIFIC_MEMBER_HEADER = 4;

	public function RenderHeader($header)
	{
		switch($header)
		{
			case self::ADD_MEMBER_HEADER;
				return "<h2>Add new member</h2>";
				break;		
			case self::LIST_MEMBER_HEADER;
				return "<h2>Memberlist</h2>";
				break;
			case self::FULL_LIST_MEMBER_HEADER;
				return "<h2>Detailed Memberlist</h2>";
				break;
			case self::SPECIFIC_MEMBER_HEADER;
				return "<h2>Specific Member</h2>";
				break;																		
		}			
	}
		
	public function RenderCreateMember() 
	{
	    $CreateForm = "<form name='frmRegUser' id='frmRegUser' method='post'>	    		
			<p>First Name:</p>			
			<input type='text' name='$this->getFirstName' id='CreateFirstName'/><br/>
			<p>Last Name:</p>			
			<input type='text' name='$this->getLastName' id='CreateLastName' /><br/>			
			<p>Social number:</p>							
			<input type='text' name='$this->getSocialNumber' id='socialnr' /><br/> 	
						
			<input type='submit' value='Create' name='$this->getCreateSubmit' id='Create' />	
					  			
		</form>";
		
		return $CreateForm;
	}
	
	public function RenderSpecificMember(Member $member) 
	{
			$firstName = $member->GetFirstName();
		
		$ret = 	"<form name='editDeleteMember' method='post'>	    		
				
				<p>First Name:</p>			
				<input type='text' name='$this->getFirstName' value='" . $member->GetFirstName() . "'/>
				
				<p>Last Name:</p>			
				<input type='text' name='$this->getLastName' value='" . $member->GetLastName() . "' />			
				
				<p>Social number:</p>							
				<input type='text' name='$this->getSocialNumber' value='" . $member->GetSocialNr() . "' />	
				
				<input type='submit' value='Update' name='$this->getUpdateButton' />
				
				</form>";	
  
  		return $ret;
	}
	
	public function RenderSmallMemberList(MemberArray $members) 
	{
		$ret = "";
		foreach ($members->Get() as $member)
		{
			$memberLink = "?MemberID=" . $member->GetID();
   			$ret .= "<a href='$memberLink'>" . $member->GetFirstName() . " " . $member->GetLastName() . "</a>
      		<p>Member ID: " . $member->GetID() . "</p>
      		<p>Number of boats: " . $member->GetNumberOfBoats() . "</p>";
		}
  
  		return $ret;
	}
	
	public function RenderBigMemberList(MemberArray $members, BoatArray $Boats) 
	{
		$ret = "";
		$bv = new BoatView();
		foreach ($members->Get() as $member)
		{
			$memberLink = "?MemberID=" . $member->GetID();
   			$ret .= "<a href='$memberLink'>" . $member->GetFirstName() . " " . $member->GetLastName() . "</a>
      		<p>Member ID: " . $member->GetID() . "</p>
      		<p>Number of boats: " . $member->GetNumberOfBoats() . "</p>";
			
			$ret .= $bv->RenderBoatList($member->GetID(), $Boats);			
		}
  
  		return $ret;
	}
	
	public function GetFirstName() 
	{	  	
		if ($_POST[$this->getFirstName] != "")
		{			 		
			return $_POST[$this->getFirstName];
		}
		
		return false;		
	}
	
	public function GetLastName() 
	{	  	
		if ($_POST[$this->getLastName] != "")
		{					 		
			return $_POST[$this->getLastName];
		}
		
		return false;		
	}	
	
	public function GetSocialNumber() 
	{	  	
		if ($_POST[$this->getSocialNumber] != "")
		{				 		
			return $_POST[$this->getSocialNumber];
		}
		
		return false;		
	}		
	
	public function TriedToCreate() 
	{	
		if (isset($_POST[$this->getCreateSubmit]))
		{
			return true;  	
		}
				
		return false;
	   		
	}
		   					       	
} 
  

?>
  